# Author: ZengHao
# CreatTime: 2022/10/21
# FileName: main
# Description: Simple introduction of the code
import cv2
from xml.etree import ElementTree as ET
from image_processing import *
from divide_assessment import *
from cell_segmentation_by_sub import *
from cell_segmentation_by_fit import *
from cell_segmentation_by_shape import *


# 文件路径列表
image_path_list = ["./train-5/184/184.jpg", "./train-5/1308/1308.jpg", "./train-5/1310/1310.jpg",
                   "./train-5/1312/1312.jpg", "./train-5/1315/1315.jpg"]
xml_path_list = ["./train-5/184/184.xml", "./train-5/1308/1308.xml", "./train-5/1310/1310.xml",
                 "./train-5/1312/1312.xml", "./train-5/1315/1315.xml"]


def read_and_output_xml(file_path_xml):
    # 解析xml文件，形成树状结构
    tree = ET.parse(file_path_xml)
    # 获取根节点根元素
    # root = tree.getroot()
    print(tree.text)


if __name__ == '__main__':
    # （1）调用image_processing的image_show方法展示图像,save_image_by_path保存图像
    base_save_path = "./save_picture/"  # 设置图像保存的路径
    for i in range(len(image_path_list)):
        image = cv2.imread(image_path_list[i])
        image_name = image_path_list[i].split("/")[-1]
        image_show(image, image_name)
        save_image_by_path(image_path_list[i], base_save_path + image_name)
    # （2）读取输出每个图像对应的xml文件
    # 在实现xml文件数据和图像结构比较的时候实现了xml文件的比较和输出
    # （3）比较所有xml文件中的宽、高和通道数与对应的图像本身是否一致，在方法内
    # 调用了单个比较函数compare_image_xml实现单个图像对比。
    # flag = compare_all_image_xml(xml_path_list, image_path_list)
    # if flag:
    #     print("所有的xml文件结构中的长宽和通道数与对应的图像相同")
    # else:
    #     print("两者之间存在不同")
    # # （4）统计图像细胞的数目
    # cell_number = []
    # for i  in range(len(image_path_list)):
    #     cell_number.append(get_cell_number_xml(file_path_xml=xml_path_list[i]))
    # print(cell_number)
    # # （5）展示绘制细胞的外接矩形
    # for i in range(len(image_path_list)):
    #     draw_cell_rect(file_path_xml=xml_path_list[i], file_path_image=image_path_list[i])
    # # （6）展示绘制出的最佳图像并输出图像评估的指标，
    # test_sub_method_performance(xml_path_list,image_path_list)
